package com.common.result.demo.controller;

import com.common.result.demo.domain.UserVo;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by zhanghy on 2019-09-19
 * description
 */

@RestController
@RequestMapping("/users")
public class UserController {

    @Value("${zhy.test}")
    private String test;

    @GetMapping("")
    public List<UserVo> getUserList() {
        List<UserVo> userVoList = Lists.newArrayListWithCapacity(2);
        userVoList.add(UserVo.builder().id(1L).name("日拱一兵").age(18).build());
        userVoList.add(UserVo.builder().id(2L).name("tan").age(19).build());
        return userVoList;
    }

    @GetMapping("/{id}")
    public UserVo getUserByName(@PathVariable Long id) {
        return UserVo.builder().id(1L).name("日拱一兵").age(18).build();
    }

    @GetMapping("/testResponseEntity")
    public ResponseEntity getUserByAge() {
        return new ResponseEntity(UserVo.builder().id(1L).name("日拱一兵").age(18).build(), HttpStatus.OK);
    }

    @GetMapping("/getTest")
    public UserVo getTest() {
        return UserVo.builder().name(test).build();
    }
}
